﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using MegaSportsStore.Domain.MegaAbstract;
using MegaSportsStore.Domain.MegaEntities;
using Moq;
using System.Collections.Generic;
using System.Linq;
using MegaSportsStore.WebUI.Controllers;

namespace MegaSportsStore.UnitTests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void Can_Paginate()
        {
            // Arrange
            Mock<IMegaProductRepository> mock = new Mock<IMegaProductRepository>();
            mock.Setup(m => m.MegaProducts).Returns(new List<MegaProduct> {
                new MegaProduct {Id = 1, Name = "P1"},
                new MegaProduct {Id = 2, Name = "P2"},
                new MegaProduct {Id = 3, Name = "P3"},
                new MegaProduct {Id = 4, Name = "P4"},
                new MegaProduct {Id = 5, Name = "P5"}
            }.AsQueryable());

            MegaProductController controller = new MegaProductController(mock.Object);

            // Act
            // Display only the 3rd page contents
            IEnumerable<MegaProduct> result = (IEnumerable<MegaProduct>)(controller.List(3).Model);

            // Assert
            MegaProduct[] prodArray = result.ToArray();
            Assert.IsTrue(prodArray.Length == 1);
            Assert.AreEqual(prodArray[0].Name, "P5");            
        }
    }
}
